
package de.swta.freezay.database.wicketAdapter;

import de.swta.freezay.database.JPAController;
import de.swta.freezay.database.dbEntities.Item;
import java.util.Iterator;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;

/**
 * A SortableDataProvider for item entities
 *
 * @author Christian Baeumer
 * @see SortableDataProvider
 */
public class ItemDataProvider extends SortableDataProvider<Item>  {

    public ItemDataProvider() {
        setSort("name", true);
    }

    @Override
    public Iterator iterator(int first, int count) {
        SortParam sp = getSort();

        return JPAController.ItemJpaController.findItemEntities(
                count, first, sp.getProperty(), sp.isAscending()).iterator();
    }

    @Override
    public int size() {
        return JPAController.ItemJpaController.getItemCount();
    }

    @Override
    public IModel<Item> model(Item i) {
        return new DetachableItemModel(i);
    }

    @Override
    public void detach() {
    }
    
}